const Column = require('./../models/columnModel');
const User = require('./../models/userModel');
const catchAsync = require('./../utils/catchAsync.js');
const AppError = require('./../utils/appError.js');
const APIFeatures = require('./../utils/apiFeatures.js');
const factory = require('./handlerFactory');
exports.setColumnUserId = (req, res, next) => {
  // Allow nested routes
  // if (!req.body.tour) req.body.tour = req.params.tourId;
  if (!req.body.user) req.body.user = req.user.id;
  next();
};
// 查找当前用户的专栏的数组
exports.findUserColumn = async (req, res, next) => {
  // const user = req.user;
  const user = await User.findById(req.user.id).populate('column');
  // 返回用户的专栏的数组
  res.status(200).json({
    results: user.column.length,
    status: 'success',
    columns: user.column,
    message: 'The User columnList',
  });
};
exports.getAllColumns = factory.getAll(Column);

exports.getColumn = factory.getOne(Column);
exports.createColumn = factory.createOne(Column);
exports.updateColumn = factory.updateOne(Column);
exports.deleteColumn = factory.deleteOne(Column);
